<?php

use App\Http\Controllers\Activity\Merchant\ShopActivityController;
use App\Http\Controllers\Activity\Merchant\ShopOrderActivityController as MerchantShopOrderActivityController;
use App\Http\Controllers\Activity\Web\ActivityController;
use App\Http\Controllers\Activity\Web\ActivityDataController;
use App\Http\Controllers\Activity\Web\ShopOrderActivityController;
use App\Http\Controllers\Activity\Merchant\ShopOrderActivityFeedbackController;
use App\Http\Middleware\OpenShop\FeishuWebAuth;
use App\Http\Middleware\OpenShop\MerchantAppAuth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Activity\Web\ActivityAuditController;
use App\Http\Middleware\Common\LockBefore;
use App\Http\Middleware\Common\LockAfter;

/**
 *
 * 群聊路由文件
 */

Route::get('test', function () {
    return 'B端门店活动';
});

// 商家app
Route::prefix('merchant')
     ->middleware(MerchantAppAuth::class)
     ->group(function () {

         // 老 - 废弃.....................
         Route::prefix('shopOrderActivity')->group(function () {
             // 活动报名
             Route::post('apply', [MerchantShopOrderActivityController::class, 'apply']);
             // 活动详情
             Route::get('detail', [MerchantShopOrderActivityController::class, 'detail']);
         });

         // 老 - 废弃.....................
         Route::prefix('feedback')->group(function () {
             // 获取反馈详情
             Route::get('detail', [ShopOrderActivityFeedbackController::class, 'detail']);
             // 提交反馈
             Route::post('save', [ShopOrderActivityFeedbackController::class, 'save']);
         });


         // 新活动
         Route::prefix('activity')->group(
             function () {
                 Route::prefix('dominatingScreen')->group(function () {// APP霸屏相关接口

                     // 霸屏通用接口
                     Route::get('/', [ShopActivityController::class, 'dominatingScreen']);

                     // 霸屏活动信息显示
                     Route::get('/activityDetail', [ShopActivityController::class, 'getActivityInfo']);
                 });

                 Route::prefix('shopOrderActivity')->group(function () {

                     // 活动-创建门店参与记录
                     Route::post('createOrder', [ShopActivityController::class, 'createOrder'])->middleware([
                         LockBefore::class . ":" . LockBefore::LOCK_TYPE_HEADER_SHOP_ID . ':5',
                         LockAfter::class . ':' . LockBefore::LOCK_TYPE_HEADER_SHOP_ID
                     ]);

                     // 活动-取消订单
                     Route::post('cancelOrder', [ShopActivityController::class, 'cancelOrder'])->middleware([
                         LockBefore::class . ":" . LockBefore::LOCK_TYPE_MERCHANT_USER_ID . ':5',
                         LockAfter::class . ':' . LockBefore::LOCK_TYPE_MERCHANT_USER_ID
                     ]);

                     // 表单新增记录
                     Route::post('inputs/add', [ShopActivityController::class, 'inputsAdd'])->middleware([
                         LockBefore::class . ":" . LockBefore::LOCK_TYPE_MERCHANT_USER_ID . ':5',
                         LockAfter::class . ':' . LockBefore::LOCK_TYPE_MERCHANT_USER_ID
                     ]);
                     Route::get('inputs/info', [ShopActivityController::class, 'inputsInfo']);// 表单记录详情
                     Route::post('inputs/update', [ShopActivityController::class, 'inputsUpdate']);// 表单记录修改

                     // 表单记录提交
                     Route::post('inputs/submit', [ShopActivityController::class, 'inputsSubmit'])->middleware([
                         LockBefore::class . ":" . LockBefore::LOCK_TYPE_MERCHANT_USER_ID . ':5',
                         LockAfter::class . ':' . LockBefore::LOCK_TYPE_MERCHANT_USER_ID
                     ]);

                 });

                 Route::prefix('feedback')->group(function () {

                     // 获取反馈详情
                     Route::get('/detail', [ShopActivityController::class, 'feedbackDetail']);

                     // 提交反馈
                     Route::post('/save', [ShopActivityController::class, 'feedbackSave'])->middleware([
                         LockBefore::class . ":" . LockBefore::LOCK_TYPE_MERCHANT_USER_ID . ':5',
                         LockAfter::class . ':' . LockBefore::LOCK_TYPE_MERCHANT_USER_ID
                     ]);
                 });

             }
         );
     });

// web端后台路由
Route::prefix('web')->middleware([FeishuWebAuth::class])->group(function () {

    // 老 - 废弃.....................
    Route::prefix("shopOrderActivity")->group(function () {// 品牌活动管理
        Route::get("/", [ShopOrderActivityController::class, "list"]);// 列表
        Route::get("/{id}", [ShopOrderActivityController::class, "detail"])->where('id', '[0-9]+');// 详情
        Route::post("/", [ShopOrderActivityController::class, "insert"]);// 新增
        Route::put("/{id}", [ShopOrderActivityController::class, "update"])->where('id', '[0-9]+');// 编辑
        Route::patch("/status/{id}", [ShopOrderActivityController::class, "status"])->where('id', '[0-9]+');// 发布|暂停
        Route::patch("/finish/{id}", [ShopOrderActivityController::class, "finish"])->where('id', '[0-9]+');// 结束
        Route::get("/dataStatistics", [ShopOrderActivityController::class, "dataStatistics"]);// 活动数据
        Route::get("/dataStatistics/shopList", [ShopOrderActivityController::class, "dataStatisticsShopList"]);// 活动门店列表
    });

    /**
     * 通用活动
     */
    Route::prefix("activity")->group(function(){
        Route::get("/", [ActivityController::class, "index"]);// 活动列表

        // 新建活动
        Route::post("/", [ActivityController::class, "store"])->middleware([
            LockBefore::class . ":" . LockBefore::LOCK_TYPE_WEB_USER_ID . ':5',
            LockAfter::class . ':' . LockBefore::LOCK_TYPE_WEB_USER_ID
        ]);
        Route::put("/{id}", [ActivityController::class, "update"])->where('id', '[0-9]+');// 更新活动
        Route::get("/{id}", [ActivityController::class, "show"])->where('id', '[0-9]+');// 活动详情
        Route::patch("/status/{id}", [ActivityController::class, "status"])->where('id', '[0-9]+');// 发布|暂停|启用
        Route::patch("/finish/{id}", [ActivityController::class, "finish"])->where('id', '[0-9]+');// 结束
        Route::get("/joinStatistics", [ActivityDataController::class, "joinStatistics"]);// 活动数据列表
        Route::get("/joinStatisticsShopList", [ActivityDataController::class, "joinStatisticsShopList"]);// 活动门店数据列表
    });

    /**
     * 审核
     */
    Route::prefix('audit')->group(function () {

        // enums
        Route::get('enums', [ActivityAuditController::class, 'enums']);

        // 列表
        Route::get('lists', [ActivityAuditController::class, 'lists']);

        // 详情
        Route::get('detail/{id}', [ActivityAuditController::class, 'detail']);

        // 审核通过/驳回
        Route::post('agree/{id}', [ActivityAuditController::class, 'agree'])->middleware([
            LockBefore::class . ":" . LockBefore::LOCK_TYPE_RESTFUL_ID . ':10',
            LockAfter::class . ':' . LockBefore::LOCK_TYPE_RESTFUL_ID
        ]);
    });
});
